package com.hcbd.tdwt.ui.common.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;

import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.hcbd.tdwt.R;


/**
 * - @Description:  警告框
 * - @Author:  LXJ
 * - @Time:  2018/12/6 18:20
 */

public class WarnDialog extends DialogFragment {
    private Activity mContext;
    private View.OnClickListener onClickListener;
    private String warnStr;


    public WarnDialog() {

    }

    public void setData(Activity context, String str, View.OnClickListener onClickListener) {
        this.mContext = context;
        this.warnStr = str;
        this.onClickListener = onClickListener;
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.9), ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        setCancelable(false);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View viewContent = inflater.inflate(R.layout.dialog_warn, container, false);
        //去掉dialog默认标题
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        //警告标题
        TextView warnTv = viewContent.findViewById(R.id.warn_dialog_tv);
        warnTv.setText(warnStr);
        //确定按钮
        Button cancelBtn = viewContent.findViewById(R.id.warn_cancel_btn);
        cancelBtn.setOnClickListener(onClickListener);
        return viewContent;
    }
}
